package edu.scnu.fans.fingertip.order.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import edu.scnu.fans.fingertip.order.output.OrderItemOutput;
import lombok.Data;

import java.math.BigDecimal;
import java.time.Instant;

/**
 * 订单商品表
 */
@Data
@TableName("order_item")
public class OrderItem {

    @TableId(type = IdType.AUTO)
    private Long id;

    private Instant created;
    private Instant updated;
    private boolean deleted;

    /** 用户id */
    private Long userId;
    /** 订单id */
    private Long orderId;
    /** 商品id */
    private Long itemId;
    /** 商品名 */
    private String itemTitle;
    /** 商品图片 */
    private String itemImgUrl;
    /** 商品规格id */
    private Long itemSpecId;
    /** 商品规格名 */
    private String itemSpecName;
    /** 价格 */
    private BigDecimal price;
    /** 购买数量 */
    private Integer amount;

    OrderItem() {
    }

    public OrderItem(Long userId, Long orderId, Long itemId, Long itemSpecId) {
        this.userId = userId;
        this.orderId = orderId;
        this.itemId = itemId;
        this.itemSpecId = itemSpecId;
    }

    public OrderItemOutput transferToOutput() {
        return new OrderItemOutput(id, created, updated, userId, orderId, itemId, itemTitle, itemImgUrl, itemSpecId,
                itemSpecName, price, amount);
    }
}
